package com.culturalCenter.dataCenter.controller.web;

import com.culturalCenter.dataCenter.Utils.ApiResult;
import com.culturalCenter.dataCenter.Utils.ResultCode;
import com.culturalCenter.dataCenter.customEntity.activity.*;
import com.culturalCenter.dataCenter.customEntity.responseParam.activity.*;
import com.culturalCenter.dataCenter.customEntity.training.CustomAttendanceList;
import com.culturalCenter.dataCenter.customEntity.training.CustomRegistrationList;
import com.culturalCenter.dataCenter.customEntity.training.CustomSignInList;
import com.culturalCenter.dataCenter.entity.activity.Activity;
import com.culturalCenter.dataCenter.entity.activity.ActivityMonitorPersonnel;
import com.culturalCenter.dataCenter.entity.activity.ActivitySiteMonitor;
import com.culturalCenter.dataCenter.globalconfig.Interface.ApiVersion;
import com.culturalCenter.dataCenter.globalconfig.Interface.CustomVersion;
import com.culturalCenter.dataCenter.param.ServiceVolumeParam;
import com.culturalCenter.dataCenter.service.activity.*;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

import static com.culturalCenter.dataCenter.Utils.ApiResult.instance;

/**
 * 活动
 *
 * @author : weicai
 * @date : 10:54 2020/10/28
 */
@RestController
@RequestMapping("/{version}/activity")
@Api(tags = "活动模块")
@ApiVersion(CustomVersion.VERSION_1)
@Slf4j
public class ActivityController {

    @Resource
    public ActivityResourceService activityResourceService;
    @Resource
    private ActivityPopularAnalysisService activityPopularAnalysisService;
    @Resource
    private ActivityService activityService;
    @Resource
    private ActivityTimeLineService activityTimeLineService;
    @Resource
    private ActivityAudienceService activityAudienceService;
    @Resource
    private ActivityAssessmentService activityAssessmentService;
    @Resource
    private ActivitySiteMonitorService activitySiteMonitorService;
    @Resource
    private ActivityPromotionAnalysisService activityPromotionAnalysisService;
    @Resource
    private ActivityServedNumberService activityServedNumberService;

    /**
     * 首页_今日举办活动数
     */
    @ApiOperation(value = "首页的今日已举办活动数", notes = "首页中的今日已举办活动数")
    @GetMapping("/todayFinishActivity")
    public ApiResult<CustomActivityTodayFinish> getTodayFinishActivity() {
        CustomActivityTodayFinish activityTodayFinish = activityService.getTodayFinishActivity();
        return instance(ResultCode.SUCCESS, activityTodayFinish);
    }

    /**
     * 活动首页
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "branchId", value = "分馆id", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "startDate", value = "开始日期", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "endDate", value = "结束日期", paramType = "query", dataType = "String")
    })
    @ApiOperation(value = "活动首页", notes = "活动首页，可切换不同分馆")
    @GetMapping("/menu")
    public ApiResult<ActivityMenuResponse> getMenu(@RequestParam(required = false) String branchId, String startDate, String endDate,String type) {
        ActivityMenuResponse activityMenuResponse = activityService.getMenu(branchId, startDate, endDate,type);
        return instance(ResultCode.SUCCESS, activityMenuResponse);
    }

    /**
     * 活动左侧列表
     */
    @GetMapping("/activityList")
    @ApiOperation(value = "活动左侧列表", notes = "活动左侧列表，可切换不同分馆")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "activityName", value = "项目名称", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "status", value = "状态", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "branchId", value = "分馆id", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "pageNum", value = "页码", paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "pageSize", value = "页码尺寸", paramType = "query", dataType = "int")
    })
    public ApiResult<ActivityListResponse> getActivityList(@RequestParam(required = false) String activityName,
                                                           @RequestParam(required = false) String status,
                                                           @RequestParam(required = false) String branchId,
                                                           @RequestParam(required = false, defaultValue = "1") int pageNum,
                                                           @RequestParam(required = false, defaultValue = "14") int pageSize) {
        ActivityListResponse activityListResponse = activityService.getActivityList(activityName, status, branchId, pageNum, pageSize);
        return instance(ResultCode.SUCCESS, activityListResponse);
    }

    /**
     * 活动基本信息
     */
    @GetMapping("/activityInfo")
    @ApiOperation(value = "活动基本信息", notes = "活动基本信息")
    @ApiImplicitParams(@ApiImplicitParam(name = "activityId", value = "活动id", paramType = "query", dataType = "String"))
    public ApiResult<ActivityInfoResponse> getActivityInfo(@RequestParam String activityId) {
        ActivityInfoResponse activityInfoResponse = activityService.getActivityInfo(activityId);
        return instance(ResultCode.SUCCESS, activityInfoResponse);
    }

    /**
     * 活动详情
     */
    @GetMapping("/activityInfo/detail")
    @ApiOperation(value = "活动详情", notes = "活动详情")
    @ApiImplicitParams(@ApiImplicitParam(name = "activityId", value = "活动id", paramType = "query", dataType = "String"))
    public ApiResult<Activity> getActivityInfoDetail(@RequestParam String activityId) {
        Activity activity = activityService.getActivityInfoDetail(activityId);
        return instance(ResultCode.SUCCESS, activity);
    }

    /**
     * 时间轴
     */
    @GetMapping("/timeLine")
    @ApiOperation(value = "时间轴", notes = "时间轴")
    @ApiImplicitParams(@ApiImplicitParam(name = "activityId", value = "活动id", paramType = "query", dataType = "String"))
    public ApiResult<ActivityTimeLineResponse> getTimeLine(@RequestParam String activityId) {
        ActivityTimeLineResponse activityTimeLineResponse = activityTimeLineService.getTimeLine(activityId);
        return instance(ResultCode.SUCCESS, activityTimeLineResponse);
    }

    /**
     * 时间轴_活动申请表格
     */
    @GetMapping("/timeLine/apply/table")
    @ApiOperation(value = "时间轴_活动申请表格", notes = "时间轴_活动申请表格")
    @ApiImplicitParams(@ApiImplicitParam(name = "activityId", value = "活动id", paramType = "query", dataType = "String"))
    public ApiResult<Activity> getApplyTable(@RequestParam String activityId) {
        Activity activity = activityService.getActivityInfoDetail(activityId);
        return instance(ResultCode.SUCCESS, activity);
    }

    /**
     * 时间轴_活动审核表格
     */
    @GetMapping("/timeLine/verify/table")
    @ApiOperation(value = "时间轴_活动审核表格", notes = "时间轴_活动审核表格")
    @ApiImplicitParams(@ApiImplicitParam(name = "activityId", value = "活动id", paramType = "query", dataType = "String"))
    public ApiResult<CustomActivityVerifyTable> getVerifyTable(@RequestParam String activityId) {
        CustomActivityVerifyTable verifyTable = activityTimeLineService.getVerifyTable(activityId);
        return instance(ResultCode.SUCCESS, verifyTable);
    }

    /**
     * 时间轴_活动报名清单
     */
    @GetMapping("/timeLine/registration/list")
    @ApiOperation(value = "时间轴_活动报名清单", notes = "时间轴_活动报名清单")
    @ApiImplicitParams(@ApiImplicitParam(name = "activityId", value = "活动id", paramType = "query", dataType = "String"))
    public ApiResult<List<CustomRegistrationList>> getRegistrationList(@RequestParam String activityId) {
        List<CustomRegistrationList> registrationList = activityTimeLineService.getRegistrationList(activityId);
        return instance(ResultCode.SUCCESS, registrationList);
    }

    /**
     * 时间轴_活动签到清单
     */
    @GetMapping("/timeLine/signIn/list")
    @ApiOperation(value = "时间轴_活动签到清单", notes = "时间轴_活动签到清单")
    @ApiImplicitParams(@ApiImplicitParam(name = "activityId", value = "活动id", paramType = "query", dataType = "String"))
    public ApiResult<List<CustomSignInList>> getSignInList(@RequestParam String activityId) {
        List<CustomSignInList> signInList = activityTimeLineService.getSignInList(activityId);
        return instance(ResultCode.SUCCESS, signInList);
    }

    /**
     * 时间轴_活动考勤清单
     */
    @GetMapping("/timeLine/attendance/list")
    @ApiOperation(value = "时间轴_活动考勤清单", notes = "时间轴_活动考勤清单")
    @ApiImplicitParams(@ApiImplicitParam(name = "activityId", value = "活动id", paramType = "query", dataType = "String"))
    public ApiResult<List<CustomAttendanceList>> getAttendanceList(@RequestParam String activityId) {
        List<CustomAttendanceList> signInList = activityTimeLineService.getAttendanceList(activityId);
        return instance(ResultCode.SUCCESS, signInList);
    }

    /**
     * 时间轴_现场_监控画面
     */
    @GetMapping("/timeLine/monitorPicture")
    @ApiOperation(value = "时间轴_监控画面", notes = "时间轴_监控画面")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "activityId", value = "活动id", paramType = "query", dataType = "String")
    })
    public ApiResult<List<ActivitySiteMonitor>> getMonitorPicture(@RequestParam String activityId) {
        List<ActivitySiteMonitor> pictureList = activityTimeLineService.getMonitorPicture(activityId);
        return instance(ResultCode.SUCCESS, pictureList);
    }

    /**
     * 受众分析
     */
    @GetMapping("/audienceAnalysis")
    @ApiOperation(value = "受众分析", notes = "受众分析")
    @ApiImplicitParams(@ApiImplicitParam(name = "activityId", value = "活动id", paramType = "query", dataType = "String"))
    public ApiResult<ActivityAudienceResponse> getAudienceAnalysis(@RequestParam String activityId) {
        ActivityAudienceResponse activityAudienceResponse = activityAudienceService.getAudienceAnalysis(activityId);
        return instance(ResultCode.SUCCESS, activityAudienceResponse);
    }

    /**
     * 推广分析
     */
    @GetMapping("/promotionAnalysis")
    @ApiOperation(value = "推广分析", notes = "推广分析")
    public ApiResult<ActivityPromotionAnalysisResponse> getPromotionAnalysis(String activityId) {
        ActivityPromotionAnalysisResponse activityPromotionAnalysisResponse = activityPromotionAnalysisService.getPromotionAnalysis(activityId);
        return instance(ResultCode.SUCCESS, activityPromotionAnalysisResponse);
    }

    /**
     * 受欢迎分析
     */
    @GetMapping("/popularAnalysis")
    @ApiOperation(value = "受欢迎分析", notes = "受欢迎分析")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "activityId", value = "活动id", paramType = "query", dataType = "String")
    })
    public ApiResult<ActivityPopularAnalysisResponse> getPopularAnalysis(@RequestParam String activityId) {
        ActivityPopularAnalysisResponse activityPopularAnalysisResponse = activityPopularAnalysisService.getPopularAnalysisData(activityId);
        return instance(ResultCode.SUCCESS, activityPopularAnalysisResponse);
    }

    /**
     * 受欢迎分析_评分评论列表
     */
    @GetMapping("/popularAnalysis/comment/list")
    @ApiOperation(value = "受欢迎分析_评分评论列表", notes = "受欢迎分析_评分评论列表")
    @ApiImplicitParams(@ApiImplicitParam(name = "activityId", value = "活动id", paramType = "query", dataType = "String"))
    public ApiResult<List<CustomActivityCommentList>> getPopularAnalysisCommentList(@RequestParam String activityId) {
        List<CustomActivityCommentList> customActivityCommentList = activityPopularAnalysisService.getCommentList(activityId);
        return instance(ResultCode.SUCCESS, customActivityCommentList);
    }

    /**
     * 图片视频
     */
    @GetMapping("/resource")
    @ApiOperation(value = "图片视频", notes = "图片视频")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "activityId", value = "活动id", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "pageNum", value = "页码", paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "pageSize", value = "页面尺寸", paramType = "query", dataType = "int"),
    })
    public ApiResult<ActivityResourceResponse> getPictureAndVideo(@RequestParam String activityId,
                                                                  @RequestParam(required = false, defaultValue = "1") int pageNum,
                                                                  @RequestParam(required = false, defaultValue = "10") int pageSize) {
        ActivityResourceResponse activityResourceResponse = activityResourceService.getPictureAndVideo(activityId, pageNum, pageSize);
        return instance(ResultCode.SUCCESS, activityResourceResponse);
    }

    /**
     * 现场监控
     */
    @GetMapping("/siteMonitor")
    @ApiOperation(value = "现场监控", notes = "现场监控")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "activityId", value = "活动id", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "pageNum", value = "页码", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "pageSize", value = "页码尺寸", paramType = "query", dataType = "String")
    })
    public ApiResult<ActivitySiteMonitorResponse> getSiteMonitor(@RequestParam String activityId, @RequestParam(required = false, defaultValue = "1") int pageNum, @RequestParam(required = false, defaultValue = "15") int pageSize) {
        ActivitySiteMonitorResponse activitySiteMonitorResponse = activitySiteMonitorService.getSiteMonitor(activityId, pageNum, pageSize);
        return instance(ResultCode.SUCCESS, activitySiteMonitorResponse);
    }

    /**
     * 现场监控_异常情况（包括图片）
     */
    @GetMapping("/siteMonitor/exception")
    @ApiOperation(value = "现场监控_异常情况", notes = "现场监控_异常情况")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "activityId", value = "活动id", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "pageNum", value = "页码", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "pageSize", value = "页码尺寸", paramType = "query", dataType = "String")
    })
    public ApiResult<PageInfo<CustomActivityException>> getException(@RequestParam String activityId,
                                                                     @RequestParam(required = false, defaultValue = "1") int pageNum,
                                                                     @RequestParam(required = false, defaultValue = "15") int pageSize) {
        PageInfo<CustomActivityException> exceptionPageInfo = activitySiteMonitorService.getException(activityId, pageNum, pageSize);
        return instance(ResultCode.SUCCESS, exceptionPageInfo);
    }

    /**
     * 现场监控_出入人员_监控画面
     */
    @GetMapping("/siteMonitor/person/picture")
    @ApiOperation(value = "现场监控_出入人员_监控画面", notes = "现场监控_出入人员_监控画面")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "activityId", value = "活动id", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "userId", value = "用户id", paramType = "query", dataType = "String")
    })
    public ApiResult<List<ActivityMonitorPersonnel>> getPersonMonitorPicture(@RequestParam String activityId, @RequestParam String userId) {
        List<ActivityMonitorPersonnel> monitorPicture = activitySiteMonitorService.getPersonMonitorPicture(activityId, userId);
        return instance(ResultCode.SUCCESS, monitorPicture);
    }

    /**
     * 信息屏：查询广州市馆所有活动
     */
    @GetMapping("/informationScreen")
    @ApiOperation(value = "信息屏：查询广州市馆所有活动", notes = "信息屏：查询广州市馆所有活动")
    public ApiResult<List<Activity>> getActivityInformationScreen() {
        List<Activity> activityInformationScreen = activityService.getAllActivityByBranchId();
        return instance(ResultCode.SUCCESS, activityInformationScreen);
    }

    /**
     * 信息屏：根据场地查询活动
     */
    @GetMapping("/informationScreen/site")
    @ApiOperation(value = "信息屏：根据场地查询活动", notes = "信息屏：根据场地查询活动")
    @ApiImplicitParam(name = "siteCode", value = "场地编码", paramType = "query", dataType = "String")
    public ApiResult<CustomSiteActivity> getSiteActivityInformationScreen(String siteCode) {
        CustomSiteActivity activityScreenInfo = activityService.getActivityBySiteCode(siteCode);
        return instance(ResultCode.SUCCESS, activityScreenInfo);
    }

    /**
     * 信息屏：查询举办中的活动
     */
    @GetMapping("/informationScreen/status")
    @ApiOperation(value = "信息屏：查询举办中的活动", notes = "信息屏：查询举办中的活动")
    public ApiResult<List<Activity>> getActivityStatusInformationScreen() {
        List<Activity> activityScreenInfo = activityService.getActivityByStatus();
        return instance(ResultCode.SUCCESS, activityScreenInfo);
    }

    /**
     * 智慧屏
     */
    @GetMapping("/smartDisplay")
    @ApiOperation(value = "场馆智慧屏", notes = "场馆智慧屏")
    @ApiImplicitParam(name = "branchId", value = "分馆id", paramType = "query", dataType = "String")
    public ApiResult<SmartDisplayResponse> getSmartDisplayInformation(String branchId) {
        SmartDisplayResponse smartDisplayResponse = activityService.getSmartDisplayInformation(branchId);
        return instance(ResultCode.SUCCESS, smartDisplayResponse);
    }

    /**
     * 导航屏
     */
    @GetMapping("/navigationScreen")
    @ApiOperation(value = "导航屏", notes = "导航屏")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "branchId", value = "分馆id", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "pageNum", value = "页码", paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "pageSize", value = "页码尺寸", paramType = "query", dataType = "int")
    })
    public ApiResult<List<Activity>> getNavigationScreen(@RequestParam(required = false) String branchId,
                                                         @RequestParam(required = false, defaultValue = "1") int pageNum,
                                                         @RequestParam(required = false, defaultValue = "7") int pageSize) {
        List<Activity> activityList = activityService.getNavigationScreen(branchId, pageNum, pageSize);
        return instance(ResultCode.SUCCESS, activityList);
    }

    /**
     * 大数据屏：线上服务人数和线下服务人数的添加
     */
    @PostMapping("/insertServerNumber")
    @ApiOperation(value = "大数据屏", notes = "大数据屏线上线下服务人数的添加")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "branchId", value = "分馆id", paramType = "insert", dataType = "String"),
            @ApiImplicitParam(name = "date", value = "日期", paramType = "insert", dataType = "String"),
            @ApiImplicitParam(name = "onLineNumber", value = "线上服务人数", paramType = "insert", dataType = "int"),
            @ApiImplicitParam(name = "offLineNumber", value = "线下服务人数", paramType = "insert", dataType = "int")
    })
    public ApiResult setServerNumber(@RequestParam(required = false, defaultValue = "462673814262349824") String branchId,
                                     @RequestParam(required = true) String date,
                                     @RequestParam(required = true) int onLineNumber,
                                     @RequestParam(required = true) int offLineNumber) {
        String result = activityServedNumberService.insertServerNumber(branchId,date,onLineNumber,offLineNumber);
        return instance(ResultCode.SUCCESS, result);
    }

   /* *//**
     * 大数据屏：查询今年总服务人数
     *//*
    @PostMapping("/insertServerNumber")
    @ApiOperation(value = "大数据屏添加", notes = "大数据屏")
    public void findServerNumber(@RequestParam(required = false, defaultValue = "462673814262349824") String branchId,
                                     @RequestParam(required = true) Date date,
                                     @RequestParam(required = true) int onLineNumber,
                                     @RequestParam(required = true) int offLineNumber) {
        int result = activityServedNumberService.insertServerNumber(branchId,date,onLineNumber,offLineNumber);
        // return instance(ResultCode.SUCCESS, result);
    }*/

    /**
     * 添加活动/培训的线上服务人数
     * @param param
     * @return
     */
    @PostMapping("/addServiceVolume")
    public ApiResult addServiceVolume(@RequestBody ServiceVolumeParam param){
        activityServedNumberService.addServiceVolume(param);
        return instance();
    }
}
